<?php

namespace app\backend\controller;

class ZhExchangeSetting extends Admin
{
    public function index()
    {
        if (!$this->request->isAjax()) {
            return view('index');
        } else {
            $res = \app\backend\model\ZhExchangeSetting::where(['id' => 1])->find();
            return json(['rows' => [$res], 'total' => 1]);
        }
    }

    public function update(){
        if (!$this->request->isAjax()) {
            $res = \app\backend\model\ZhExchangeSetting::where(['id' => 1])->find();
            $this->view->assign('info', checkData($res));
            return view('update');
        } else {
            $postField = 'expires,price';
            $data      = $this->request->only(explode(',', $postField), 'post', null);
            $res = \app\backend\model\ZhExchangeSetting::where(['id' => 1])->update($data);
            return json(['status' => '00', 'msg' => '操作成功']);
        }
    }
}